package com.lobo.blog.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lobo.blog.entity.Type;
import com.lobo.blog.exception.AllReadyBeenDeletedException;
import com.lobo.blog.exception.TypeNotFoundException;
import com.lobo.blog.mappers.TypesMapper;
import com.lobo.blog.service.AdminTypeService;
import com.lobo.blog.service.TypeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @authoer:MacieSerenity
 * @createDate: 2022/9/29
 * @description:
 */
@Service
public class TypeServiceImpl implements TypeService {

    @Resource
    TypesMapper typesMapper;


    @Override
    public Type getTypeByTypeId(Integer typeId) throws TypeNotFoundException {
        Type type = typesMapper.getTypeById(typeId);
        if (type != null) {
            return type;
        } else {
            throw new TypeNotFoundException();
        }
    }

    @Override
    public List<Type> getAllType() {
        return typesMapper.getAllTypeByList();
    }

    @Override
    public PageInfo<Type> getTypes(Integer pageNum) {
        //开启分页功能（类似于拦截器，拦截下一条查询语句，并加上limit语句）
        PageHelper.startPage(pageNum, 10);
        List<Type> list = typesMapper.getAllTypeByList();
        PageInfo page = new PageInfo(list);
        System.out.println(page);
        return page;
    }

    @Override
    public List<Type> getTopTypeBySize(Integer size) {
        return typesMapper.getTopType(size);
    }

}
